Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

267
Vistas
JS split(", ") works in Browser console but not in Node

I'm using Firefox, and tried this with node v14 and v17. I'm trying to parse a string into a date:

const extractThreadDate = (page: string): Date => {
      const $ = cheerio.load(page)
      const posthead = $("div .posthead")
      const postdate = $(".postdate", posthead)
      // format: 25/01/2010, 12:37
      const textDate = postdate.first().text().trim()
      console.log("1", textDate)
      const [dayDate, hourDate] = textDate.split(", ")
      console.log("2", [dayDate, hourDate])
      const [day, month, year] = dayDate.split("/").map(s => Number(s))
      console.log("3", [day, month, year])
      const [hour, minute] = hourDate.split(":").map(s => Number(s))
      console.log("4", [hour, minute])
      const date = new Date(year, month, day, hour, minute)
      return date
}

However the logs show the following:

1 25/01/2010, 12:37
2 [ '25/01/2010, 12:37', undefined ]
3 [ 25, 1, NaN ]

Any hints?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can regex all whitespace using /\s/g in JavaScript, so to match this, you could do .split(/,\s/g) rather than targeting arbitrary/specific whitespace characters.

about 4 years ago · Juan Pablo Isaza Denunciar

0

So, I did a sanity check and noticed that "25/01/2010, 12:37".split(", ") works correctly by itself. Weirded out, I put a fs.writeFileSync("hehehehe", textDate). Turns out there was a \u00a0 character instead of a space. Amazing. Who thought it'd be a good idea to have another whitespace? Whatever, that was it, split(",\u00a0") works fine.

The reason it worked is that when you copy it to the clipboard, it apparently gets converted into a regular whitespace.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda